package com.sxkf.template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.Coupon;
import com.sxkf.template.service.CouponService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 优惠卷表 前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-11-21 12:28:30
 */
@RestController
@RequestMapping("/coupon")
public class CouponController {

    @Resource
    private CouponService couponService;


//    @ApiOperation(value = "查询优惠券")
//    @GetMapping(value = "/page")
//    public R<List<Coupon>> page(@RequestParam String storeId){
//        List<Coupon> coupons = couponService.list(new LambdaQueryWrapper<Coupon>().eq(Coupon::getStoreId, storeId));
//        return R.success(coupons);
//    }

    @ApiOperation(value = "分页查询优惠券")
    @GetMapping(value = "/page")
    public R<IPage<Coupon>> page(@RequestParam Integer pageNo,
                                 @RequestParam Integer pageSize,
                                 @RequestParam String storeId){
        Page<Coupon> page = couponService.page(new Page<>(pageNo, pageSize), new LambdaQueryWrapper<Coupon>()
                .eq(Coupon::getStoreId, storeId));
        return R.success(page);
    }

    @ApiOperation(value = "添加优惠券")
    @PostMapping(value = "/add")
    public R<?> add(@RequestBody Coupon coupon){
        couponService.save(coupon);
        return R.success();
    }
}
